<template>
    <div class="sidebar">
        <!-- 默认颜色#324157 -->
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in navLsit">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>

                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
// import { mapState } from "vuex";

export default {
    data() {
        return {
            //根据登录的权限获取到的列表数据
            navLsit: [],
            //是否禁止展示
            collapse: false,
            items: [
                {
                    icon: 'el-icon-s-home',
                    index: 'index',
                    title: '首页'
                },

                {
                    icon: 'el-icon-s-order',
                    index: 'order',
                    title: '订单',
                    subs: [
                        {
                            index: 'orderForm',
                            title: '订货单（入驻商）'
                        },

                        {
                            index: 'creditOrder',
                            title: '退货单（入驻商）'
                        },

                        {
                            index: 'shipOrder',
                            title: '订货单（平台）'
                        }
                    ]
                },

                {
                    icon: 'el-icon-s-shop',
                    index: 'goods',
                    title: '商品',
                    subs: [
                        {
                            index: 'goodsList',
                            title: '商品列表'
                        },
                        {
                            index: 'categoryManagement',
                            title: '类目管理'
                        },
                        {
                            index: 'brandAdmin',
                            title: '品牌管理'
                        },
                        {
                            index: 'unitList',
                            title: '单位管理'
                        },
                        {
                            index: 'labelList',
                            title: '标签管理'
                        },
                        {
                            index: 'moreSizeAdmin',
                            title: '多规格管理'
                        },
                        {
                            index: 'goodsAuditRu',
                            title: '商品审核'
                        },
                        {
                            index: 'standardAudit',
                            title: '标品库商品审核'
                        },
                        {
                            index: 'rugoodsAudit',
                            title: '入驻商商品审核'
                        }
                    ]
                },

                {
                    icon: 'el-icon-s-custom',
                    index: 'user',
                    title: '客户',
                    subs: [
                        {
                            index: 'businessAdmin',
                            title: '入驻商管理'
                        },
                        {
                            index: 'userAdmin',
                            title: '用户管理'
                        },
                        {
                            index: 'areaAdmin',
                            title: '区域管理'
                        },
                        {
                            index: 'VIPsetting',
                            title: '会员设置'
                        },
                        {
                            index: 'userAppeal',
                            title: '用户申诉'
                        },
                        {
                            index: 'usrLabel',
                            title: '标签管理'
                        }
                    ]
                },

                {
                    icon: 'el-icon-coin',
                    index: 'inventory',
                    title: '库存',
                    subs: [
                        {
                            index: 'goodsInventory',
                            title: '商品库存状况'
                        }
                    ]
                },

                {
                    icon: 'el-icon-pie-chart',
                    index: 'marketingGoods',
                    title: '营销-商品部',
                    subs: [
                        {
                            index: 'orderPromotionGoods',
                            title: '订单促销'
                        },
                        {
                            index: 'goodsPromotionGoods',
                            title: '商品促销'
                        }
                        // {
                        //     index: 'groupPromotion',
                        //     title: '团购促销'
                        // },

                        // {
                        //     index: 'packagePromotion',
                        //     title: '套餐促销'
                        // },
                        // {
                        //     index: 'seckillActivity',
                        //     title: '秒杀活动'
                        // },
                        // {
                        //     index: 'coupon',
                        //     title: '优惠券'
                        // }
                    ]
                },
                {
                    icon: 'el-icon-s-data',
                    index: 'marketing',
                    title: '营销-平台',
                    subs: [
                        {
                            index: 'orderPromotion',
                            title: '订单促销'
                        },
                        {
                            index: 'goodsPromotion',
                            title: '商品促销'
                        },
                        {
                            index: 'groupPromotion',
                            title: '团购促销'
                        },

                        {
                            index: 'packagePromotion',
                            title: '套餐促销'
                        },
                        {
                            index: 'seckillActivity',
                            title: '秒杀活动'
                        },
                        {
                            index: 'coupon',
                            title: '优惠券'
                        }
                    ]
                },

                {
                    icon: 'el-icon-data-line',
                    index: 'marketingZi',
                    title: '营销-子机构',
                    subs: [
                        {
                            index: 'orderPromotionZi',
                            title: '订单促销'
                        },
                        {
                            index: 'goodsPromotionZi',
                            title: '商品促销'
                        },
                        {
                            index: 'groupPromotionZi',
                            title: '团购促销'
                        },

                        {
                            index: 'packagePromotionZi',
                            title: '套餐促销'
                        },
                        {
                            index: 'seckillActivityZi',
                            title: '秒杀活动'
                        },
                        {
                            index: 'auditActivityZi',
                            title: '审核入驻商活动'
                        }
                    ]
                },

                // 营销---入驻商
                {
                    icon: 'el-icon-data-analysis',
                    index: 'marketingRu',
                    title: '营销-入驻商',

                    subs: [
                        {
                            index: 'orderPromotionRu',
                            title: '订单促销'
                        },

                        {
                            index: 'goodsPromotionRu',
                            title: '商品促销'
                        },
                        {
                            index: 'groupPromotionRu',
                            title: '团购促销'
                        },

                        {
                            index: 'packagePromotionRu',
                            title: '套餐促销'
                        },
                        {
                            index: 'seckillActivityRu',
                            title: '秒杀活动'
                        },
                        {
                            index: 'couponRu',
                            title: '优惠券'
                        },

                        {
                            index: 'applyActivityRu',
                            title: '营销活动报名'
                        }
                    ]
                },

                {
                    icon: 'el-icon-s-platform',
                    index: 'webAdmin',
                    title: '前端管理-平台'
                },

                {
                    icon: 'el-icon-collection-tag',
                    index: 'webAdminRu',
                    title: '前端管理-入驻商'
                },

                {
                    icon: 'el-icon-setting',
                    index: 'system',
                    title: '系统',
                    subs: [
                        {
                            index: 'organizationAdmin',
                            title: '机构组织管理'
                        },

                        {
                            index: 'organizationAdminRu',
                            title: '机构组织管理入驻商'
                        },

                        {
                            index: 'staffId',
                            title: '帐号管理'
                        },
                        {
                            index: 'roleAdmin',
                            title: '角色权限管理'
                        },
                        {
                            index: 'systemSettings',
                            title: '系统设置'
                        },
                        {
                            index: 'operationLog',
                            title: '系统操作日志'
                        }
                    ]
                },
                {
                    icon: 'el-icon-wallet',
                    index: 'IntegralMall',
                    title: '积分商城',
                    subs: [
                        {
                            index: 'IntegralMallGoodsAdmin',
                            title: '积分商城管理'
                        },
                        {
                            //report
                            index: 'unifyIntegralAdmin',
                            title: '积分商城统一商品管理'
                        }
                    ]
                },

                {
                    icon: 'el-icon-edit-outline',
                    index: 'postMessage',
                    title: '发帖中心',
                    subs: [
                        {
                            index: 'postMessageAdmin',
                            title: '发帖管理'
                        }
                    ]
                },

                {
                    icon: 'el-icon-bell',
                    index: 'usertPushMessage',
                    title: '信息',
                    subs: [
                        {
                            index: 'usertPushMessageAdmin',
                            title: '信息管理'
                        }
                    ]
                }

                // 下面的都是框架内容
                // {
                //     icon: 'el-icon-loading',
                //     index: '3',
                //     title: '表单相关',

                //     subs: [
                //         {
                //             index: '3-2',
                //             title: '三级菜单',
                //             subs: [
                //                 {
                //                     index: 'editor',
                //                     title: '富文本编辑器'
                //                 },

                //             ]
                //         },
                //         {
                //             index: 'upload',
                //             title: '文件上传'
                //         }
                //     ]
                // },

                // {
                //     icon: 'el-icon-pie-chart',
                //     index: 'charts',
                //     title: 'schart图表'
                // },
                // {
                //     icon: 'el-icon-rank',
                //     index: '6',
                //     title: '拖拽组件',
                //     subs: [
                //         {
                //             index: 'drag',
                //             title: '拖拽列表'
                //         },
                //         {
                //             index: 'dialog',
                //             title: '拖拽弹框'
                //         }
                //     ]
                // }
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
        // 映射vuex 数据
        // ...mapState(['menuList'])
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });

        //创建时候调用获取侧边栏接口
        this.getSideBaar();
    },
    methods: {
        getSideBaar() {
            this.navLsit = JSON.parse(sessionStorage.getItem('saveMenuList'));
            console.log(this.navLsit, '我是菜单');
        }
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
